package ebcs.scan.controller.messagePushCtr;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import ebcs.scan.service.wechat.WeChatTemplPushService;
import ebcs.scan.service.wechat.bean.WechatTemplateSendData;
import ebcs.scan.service.wechat.bean.WechatTemplateSendDataDetail;
import jplat.error.exception.JSystemException;
import jplat.error.exception.JTransException;
import jplat.tools.string.DateUtil;

/***
 * 消息推送服务
 * @author chenzhuo
 * @comment
 */
@Controller
public class MessagePushCtr {
	private Logger logger = Logger.getLogger(MessagePushCtr.class);

	@Autowired
	private WeChatTemplPushService wechatPushService;
	/**
	 * 发送微信服务器
	 * @param request
	 * @param response
	 * @throws JTransException
	 * @throws JSystemException
	 */
	@RequestMapping("/page/sys/batch/messagePush.do")
	public void messagePush( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		String openid = request.getParameter("openid");
		String openUrl = request.getParameter("openUrl");
 		WechatTemplateSendData data = new WechatTemplateSendData();
		data.setFirst(new WechatTemplateSendDataDetail("您好，陈卓，我是您的小助理！", "#173177"));
		data.setKeyword1(new WechatTemplateSendDataDetail("下班前，请记得打卡和报工哦！如果你已经操作过，请飘过......", "#000000"));
		data.setKeyword2(new WechatTemplateSendDataDetail(DateUtil.getSystemTimeBySomeFormat("yyyy年MM月dd日 hh:mm:ss"), "#000000"));
		data.setRemark(new WechatTemplateSendDataDetail("请点击详情进行处理", "#000000"));
		logger.info("--------send begin");
 		wechatPushService.doSendTemplateMsg(openid, openUrl, data,0);
 		logger.info("--------send over");
	}
	
}
